package com.github.androiddevelopmentframework.record.activity;

import android.view.View;

import com.github.androiddevelopmentframework.R;
import com.github.androiddevelopmentframework.record.bean.OrderRecordBean;
import com.github.androiddevelopmentframework.record.recordInterface.RecordInterface;
import com.github.freewu.commons.libs.RefreshView;
import com.github.freewu.mvp.presenter.Presenter;
import com.github.freewu.mvp.view.BaseActivity;
import com.google.gson.JsonObject;
import com.joanzapata.android.BaseAdapterHelper;
import com.joanzapata.android.QuickAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by free on 16-8-3.
 */
public class RecordActivity extends BaseActivity implements RecordInterface.ViewInterface{

    private RefreshView<OrderRecordBean> refreshView;

    private QuickAdapter<OrderRecordBean> adapter;

    @Override
    public int getLayout() {
        return R.layout.activity_record_layout;
    }

    @Override
    public void initView(View mView) {
        refreshView=(RefreshView<OrderRecordBean>) mView.findViewById(R.id.refresh_view);
    }

    @Override
    public void initData() {
        adapter=new QuickAdapter<OrderRecordBean>(getContext(),R.layout.record_item,new ArrayList<OrderRecordBean>(5)) {
            @Override
            protected void convert(BaseAdapterHelper helper, OrderRecordBean item) {
                 helper.setText(R.id.textView2,item.getDeskname());
                 helper.setText(R.id.error_text,item.getDate());
                 helper.setText(R.id.textView4,item.getHours());
                 helper.setText(R.id.textView5,item.getSigninTime());
            }
        };

        Map<String,String> params=new HashMap<>();
        params.put("usercode","YKT1332140120");

        refreshView.setUrl("http://mob.huanghuai.edu.cn/service/libaryReserve!getMyReserveList",params);
        refreshView.setTclass(OrderRecordBean.class);
        refreshView.setPageNextIntercept(new RefreshView.PageNextIntercept() {
            @Override
            public boolean hasNext(JsonObject json) {
                if (json.get("hasNext").getAsString().equals("1")) {
                    return true;
                }else{
                    return false;
                }
            }
        });
        refreshView.setAdapter(adapter);
    }
}
